package com.aggron.concurrency.aqs;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;

/**
 * @author LR2SD
 * @description Future测试类
 * @date 2018-06-14 19:11
 */
@Slf4j
public class FutureExample {

     static class MyCallable implements Callable<String>{

         @Override
         public String call() throws Exception {
             log.info("do something");
             Thread.sleep(5000);
             return "done";
         }
     }

     public static void main(String [] args)throws Exception{
         ExecutorService executorService= Executors.newCachedThreadPool();
         Future<String> future=executorService.submit(new MyCallable());
         String result= future.get();
         log.info("result:{}",result);
         executorService.shutdown();
     }
}
